package game.efficientCollisionPrediction;

import game.SpaceObject;

import java.util.Collection;
import java.util.Date;

/**
 * A class representing the collision between two space objects. 
 * @author JeroenGillis
 *
 */
public abstract class FutureCollision implements Comparable<FutureCollision>{

	private Date collisionMoment;
	
	public abstract double getTimeToCollision();
	
	public abstract boolean isTerminated();
	
	public abstract Collection<SpaceObject> getInvolvedSpaceObjects();
	
	public abstract void collide();
	
	@Override
	public boolean equals(Object other) {
		return (this == other);
	}
	
	public Date getCollisionMoment() {
		return this.collisionMoment;
	}

	protected void setCollisionMoment(Date collisionMoment) {
		this.collisionMoment = collisionMoment;
	}	
	
	public void update() {
		Date newDate = new Date();
		if(isTerminated())
			setCollisionMoment(null);
		double timeToCollision = getTimeToCollision();
		if(Double.isInfinite(timeToCollision))
			setCollisionMoment(null);
		else {
			newDate.setTime(newDate.getTime() + (long) (timeToCollision*1000) );
			setCollisionMoment(newDate);
		}
	}
	
	@Override
	public int compareTo(FutureCollision o) {
		if(o == null)
			return -1;
		if(o.getCollisionMoment() == null)
			return -1;
		if(this.getCollisionMoment() == null)
			return +1;
		return this.getCollisionMoment().compareTo(o.getCollisionMoment());
	}
	
}
